namespace js_gaoji_day4 {

    // 递归实现深拷贝
    function deepCopy(obj: Obj) {
        if (typeof obj !== 'object' || obj === null) {
            return obj;
        }
        let result = Array.isArray(obj) ? [] : {};
        // for (let key in obj) {
        //     if (obj.hasOwnProperty(key)) {
        //         result[key] = deepCopy(obj[key as keyof Obj]) as Obj;
        //     }
        // }
        
        return result;
    }

    interface Obj {
        a: number
        b: number[]
    }
    let obj1: Obj = {
        a: 1,
        b: [1, 2, 3]
    };
    let obj2 = deepCopy(obj1) as Obj;
    obj2.b[0] = 99;
    console.log(obj1.b); // 输出 [1, 2, 3]，说明原对象没有受到影响

}